package registration.adventurezone.thevine.com;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class DBChild {
	private String childFirst;
	private String childLast;
	private String gender;
	private int[] dob;
	private int age;
	private String allergies;
	private String parentFirst;
	private String parentLast;
	private String phone;
	private String address;
	private String city;
	private String zip;
	private String churchPhone;
	private String churchPref;
	private int id = -1;
	private ArrayList<Guardian> guardians;
	
	
	public DBChild(){
		
	}
	
	public DBChild(String childFirst, String childLast, String gender, int[] dob, String allergies,
					String parentFirst, String parentLast, String phone, String address, String city,
						String zip, String churchPhone, String churchPref, int id, ArrayList<Guardian> guardians) {
		
		this.childFirst = childFirst;
		this.childLast = childLast;
		this.gender = gender;
		this.dob = dob;
		this.allergies = allergies;
		this.parentFirst = parentFirst;
		this.parentLast = parentLast;
		this.phone = phone;
		this.address = address;
		this.city = city;
		this.zip = zip;
		this.churchPhone = churchPhone;
		this.churchPref = churchPref;
		this.id = id;
		this.guardians = guardians;
	}
	public DBChild(String childFirst, String childLast, int id) {
		this.childFirst = childFirst;
		this.childLast = childLast;
		this.id = id;
	}
	/*
	 * Getters and Setters
	 */

	public String getAllergies() {
		return allergies;
	}
	public void setAllergies(String allergies) {
		this.allergies = allergies;
	}
	
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getZip() {
		return zip;
	}
	public void setZip(String zip) {
		this.zip = zip;
	}
	public ArrayList<Guardian> getGuardians() {
		return guardians;
	}
	public void setGuardians(ArrayList<Guardian> guardians) {
		this.guardians = guardians;
	}

	public String getChildFirst() {
		return childFirst;
	}

	public void setChildFirst(String childFirst) {
		this.childFirst = childFirst;
	}

	public String getChildLast() {
		return childLast;
	}

	public void setChildLast(String childLast) {
		this.childLast = childLast;
	}

	public String getParentFirst() {
		return parentFirst;
	}

	public void setParentFirst(String parentFirst) {
		this.parentFirst = parentFirst;
	}

	public String getParentLast() {
		return parentLast;
	}

	public void setParentLast(String parentLast) {
		this.parentLast = parentLast;
	}

	public int[] getDob() {
		return dob;
	}

	public void setDob(int[] dob) {
		this.dob = dob;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getGender() {
		return gender;
	}

	public void setChurchPhone(String churchPhone) {
		this.churchPhone = churchPhone;
	}

	public String getChurchPhone() {
		return churchPhone;
	}

	public String getChurchPref() {
		return churchPref;
	}

	public void setChurchPref(String churchPref) {
		this.churchPref = churchPref;
	}

	public int getID() {
		return id;
	}

	public void setID(int id) {
		this.id = id;
	}

	public int getAge() {
		Calendar now = Calendar.getInstance(TimeZone.getDefault());
		int year = convert2DigitTo4DigitYear(now.get(Calendar.YEAR), dob[2]);
		age = now.get(Calendar.YEAR) - year;
		int monthDiff = dob[0] - (now.get(Calendar.MONTH)+1);
		
		if(monthDiff > 0) {
			return age - 1;
		}
		if(monthDiff == 0) {
			int dayDiff = dob[1] - now.get(Calendar.DATE);
			if(dayDiff > 0) {
				return age - 1;
			}
		}

		return age;
	}
	private int convert2DigitTo4DigitYear(int current, int twoDigits) {
		int temp = twoDigits + 2000;
		if(temp > current) {
			return temp-100;
		}
		
		return temp;
	}

}
